package com.cp.provider;

import com.cp.api.IUserService;
import com.cp.commons.User;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.Date;

/**
 * @author feipeng
 * @site www.gcp168.cn
 * @create 2020-08-20 21:25
 */
@RestController
public class HelloController implements IUserService {
    @Value("${server.port}")
    Integer port;
    /*@GetMapping("/hello")*/
    @Override
    public String hello(){
        return "hello world" + port;
    }

   /* @GetMapping("/hello2")*/
    @Override
    public String hello2(String name){
        System.out.println(new Date() + ">>>" + name);
        return "hello" + name;
    }

    @PostMapping("/user1")
    public User addUser1(User user){
        return user;
    }

    /*@PostMapping("/user2")*/
    @Override
    public User addUser2(@RequestBody User user){
        return user;
    }

    @PutMapping("/user1")
    public void UpdateUser1(User user){
        System.out.println(user);
    }

    @PutMapping("/user2")
    public void UpdateUser2(@RequestBody User user){
        System.out.println(user);
    }

    @DeleteMapping("/user1")
    public void deleteUser1(Integer id){
        System.out.println(id);
    }

    /*@DeleteMapping("/user2/{id}")*/
    @Override
    public void deleteUser2(@PathVariable Integer id){
        System.out.println(id);
    }

    /*@GetMapping("/user3")*/
    @Override
    public void getUserByName(@RequestHeader String name) throws UnsupportedEncodingException {
        System.out.println(URLDecoder.decode(name,"UTF-8"));
    }
}